let baseUrl = 'https://m1.apifoxmock.com/m1/4728220-0-default/api/'

export default function http(url, data = {}, method = 'GET') {
	return new Promise((resolve, reject) => {
		uni.request({
			url: baseUrl + url,
			data,
			method,
			header: {
				//uni.getStorageSync(KEY)从本地缓存中同步获取指定 key 对应的内容
				'token': uni.getStorageSync('tnken') || ''
			},
			success: res => {
				//http的状态码
				if (res.statusCode == 200) {
					if (res.data.code == 1) {
						resolve(res.data.data)
					} else if (res.data.code == 0) {
						uni.showToast({ //显示消息提示框
							title: res.data.msg,
							icon: 'none'
						})
						reject(res.data.msg)
					}
				}
			},
			fail: () => { //接口调用失败的回调函数
				uni.showToast({
					title: '服务器请求异常',
					icon: 'none'
				})
			}
		})
	})
}